<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /* 
      修改对象的状态 
    */
    //#region 
    let p = new Promise((resolve, reject) => {
      // 1、resolve函数
      // resolve('OK');//pedding --> fullfilled(resolved)
      // 2、reject函数
      // reject('Error'); //pedding-->rejected
      // 3、throw
      throw '出问题了' //pedding-->rejected
    })
    console.log(p)
    //#endregion
    /* 
      能否执行多个回调-能
    */
    //#region 
    let p1 = new Promise((resolve, reject) => {
      resolve('OK');
    })
    // 指定回调 -1
    p1.then(value => {
      console.log('回调1', value)
    })
    // 指定回调 -2
    p1.then(value => {
      console.log('回调2', value)
    })
    //#endregion
    /* 
      改变状态与指定回调的顺序问题
    */
    //#region 
    let p2 = new Promise((resolve, reject) => {
      setTimeout(() => {
        resolve('OK');
      }, 1000)
    })
    // 指定回调 -1
    p2.then(value => {
      console.log(value)
    }, reason => {
      console.log(reason)
    })
    //#endregion
    /*
      then方法返回结果有什么决定
    */
    //#region
    let p3 = new Promise((resolve, reject) => {
      resolve('OK');
    })
    // 指定回调 -1
    let result = p3.then(value => {
      console.log(value)
    },reason=>{
      console.log(reason)
    })
    console.log('resault',result)
   //#endregion
   let p4 = new Promise((resolve, reject) => {
      // resolve('p4-OK');
      reject('p4-error')
    })
    p4.then(()=>{
      console.log('111')
    }).catch(error=>{
      console.log(error)
    })
  </script>
</body>

</html>